home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / c01oop.zip / ADAWKBK / SOL4-5.ADA < prev    next >
Text File  |  1992-08-25  |  1KB  |  53 lines

  1. -- Problem 4.5
  2. -- by Rick Conn
  3. with Text_IO;
  4. procedure Main is
  5.  
  6.   DIVIDE_BY_ZERO : exception;
  7.  
  8.   type INTARRAY is array (INTEGER range <>) of INTEGER;
  9.  
  10.   I1 : constant INTARRAY := (2, 3, 4, 5, 6, 7);
  11.   J1 : constant INTARRAY := (2, 0, 1, 0);
  12.   K  : INTEGER;
  13.  
  14.   package Int_IO is new Text_IO.Integer_IO (INTEGER);
  15.  
  16.   function "/" (Left, Right : in INTEGER) return INTEGER is
  17.   begin
  18.     if Right = 0 then
  19.       raise DIVIDE_BY_ZERO;
  20.     end if;
  21.     return Standard."/" (Left, Right);
  22.   end "/";
  23.  
  24.   procedure Print_ALL (I1_Index, J1_Index, K : in INTEGER) is
  25.   begin
  26.     Int_IO.Put (I1(I1_Index), 2);
  27.     Text_IO.Put ("/");
  28.     Int_IO.Put (J1(J1_Index), 2);
  29.     Text_IO.Put (" = ");
  30.     Int_IO.Put (K, 2);
  31.     Text_IO.New_Line;
  32.   end Print_All;
  33.  
  34. begin -- main
  35.  
  36.   for J in J1'RANGE loop
  37.     for I in I1'RANGE loop
  38.       begin
  39.         K := I1(I) / J1(J);
  40.         Print_All (I, J, K);
  41.       exception
  42.         when DIVIDE_BY_ZERO =>
  43.           Text_IO.Put ("Division by Zero: ");
  44.           Int_IO.Put (I1(I), 2);
  45.           Text_IO.Put (" / ");
  46.           Int_IO.Put (J1(J), 2);
  47.           Text_IO.New_Line;
  48.       end;
  49.     end loop;
  50.   end loop;
  51.  
  52. end Main;
  53.